package com.pet.pet07forum.controller;

import com.pet.pojo.Comment;
import com.pet.pojo.Topic;
import com.pet.service.ForumService;
import com.pet.vo.PageResult;
import com.pet.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/*  刘星宇  */
@RestController
@RequestMapping("/forum")
public class ForumController {

    @Autowired
    private ForumService forumService;

    @GetMapping("/topic/findAllTopicList")
    public SysResult findAllTopicList(PageResult pageResult) throws ParseException {
        pageResult = forumService.findAllTopicList(pageResult);
        return SysResult.success(pageResult);
    }
    // http://localhost:8081/topic/findTopicById?id=1
    @GetMapping("/topic/findTopicById")
    public SysResult findTopicById(Integer id){
        System.out.println(id);
        Topic topic = forumService.findATopicById(id);
        return SysResult.success(topic);
    }
    //"http://localhost:8083/forum/topic/findHotTopicList"
    @GetMapping("/topic/findHotTopicList")
    public SysResult findHotTopicList(){
        List<Topic> hotTopicList =  forumService.findHotTopicList();
        return SysResult.success(hotTopicList);
    }
    // "http://localhost:8083/forum/topic/addtopic", this.topicForm
    @PostMapping("/topic/addTopic")
    public SysResult addTopic(@RequestBody Topic topic){
        System.out.println("topic传值" + topic);
        forumService.addTopic(topic);
        return SysResult.success();
    }


    @GetMapping("/comment/findAllCommentByTopicId")
    public SysResult findAllCommentByTopicId(Integer id){
        System.out.println(id);
        List<Comment> commentList = forumService.findAllCommentByTopicId(id);
        return SysResult.success(commentList);
    }

    // http://localhost:8081/comment/saveComment
    @PostMapping("/comment/saveComment")
    public SysResult saveComment(@RequestBody Comment comment){
        System.out.println(comment);
        forumService.saveComment(comment);
        return SysResult.success();
    }

}
